<?php
/*
 * @author qianfunian
 */
// INCLUDE JCART BEFORE SESSION START

require('./configs/config.php');
// INCLUDE JCART BEFORE SESSION START
require 'jcart/jcart.php';

// START SESSION
session_start();
include 'header.php';
$cart =& $_SESSION['jcart']; if(!is_object($cart)) $cart = new jcart();

if($_SERVER['REQUEST_METHOD'] == 'POST')
{
	if ($items = & $cart->get_contents())
	{
		
		extract($_POST);
		$db->insert('s_orders', array('mobile' =>$mobilephone, 'address' => $address,'totalPrice' => $cart->total,'addTime' =>'now'));
		$orderid = & $db->insert_id();
		
		foreach ($items as $item)
		{
			$db->insert('s_items', array('orderId' =>$orderid, 'itemName' => $item['name'],'itemPrice' =>$item['price'],'itemCount' => $item['qty'],'totalPrice' =>$item['price']*$item['qty'],'addTime'=>'now'));
		}
		
		$smarty->assign('mobile',$mobilephone);
		$smarty->assign('address',$address);
		$smarty->assign('total',$cart->total);
		$smarty->assign('items',$items);
	}else
	{
		
	}
	$cart->empty_cart();
}

$smarty->display('show-order.tpl');